﻿#pragma once
#include "DataObject.h"
#include "Object.h"
#include "Types.h"

class Mesh : public Object
{
  using FaceInfo = vtkm::Pair<Id, UInt8>;
public:
  Mesh(const Configuration& cfg)
    : Object(cfg)
  {
  }
  virtual ~Mesh() = default;

  CoordinateSystem& GetCoordinate() { return this->_coord; }
  const CoordinateSystem& GetCoordinate() const { return this->_coord; }

  const vtkm::cont::DynamicCellSet& GetCellSet() const { return this->_cell_set; }
  vtkm::cont::DynamicCellSet& GetCellSet() { return this->_cell_set; }

  const ArrayHandle<Id>& GetBoundaryId() const { return this->_boundary_id; }
  ArrayHandle<Id>& GetBoundaryId() { return this->_boundary_id; }

  virtual void Build() = 0;
  /// @brief 建立Face的拓扑关系
  void BuildFaceTopo();

  ArrayHandle<FaceInfo>& GetCellLinks() { return _cell_links; }
  ArrayHandle<Id>& GetFaceNumOffset() { return _face_num_offset; }

  int _nx, _ny;

protected:
  DynamicCellSet _cell_set;
  CoordinateSystem _coord;
  ArrayHandle<Id> _boundary_id;


  ArrayHandle<Id> _face_num_offset;

  /// @brief first: cell global id, second: face local id

  /// @brief 只存放的neighbor cell的FaceInfo，因为当前cell的FaceInfo是显式的, _cell_links[cell global id][face local id]
  ArrayHandle<FaceInfo> _cell_links;
  //vtkm::cont::ArrayHandleGroupVecVariable<FaceInfo, Id> _cell_links;

  /// @brief Face的左右单元信息
  /// left cell :  _face_links[face global id][0]  -> FaceInfo
  /// right cell : _face_links[face global id][1]  -> FaceInfo
  //ArrayHandle<Vec<FaceInfo, 2>> _face_links;

  std::map<std::string, std::vector<int>> _bnd_map;
};
